auto.waitFor();
function 进入同城 () {
  位置名="test"
  while(true){
    if (text('商城').exists()){
        log('在抖音首页')
   u= id('kqq').findOne()
      if (u.bounds().left<device.width/2){
     log('已在同城')
   
    if (id('u2e').textContains(位置名).exists()){
        log('城市正确')
        break
    }else{
        log('城市不对，换城市')
               var a2 = id('u2e').findOne().bounds().centerX();
        var a3 = id('u2e').findOne().bounds().centerY();
        press(a2, a3, 1)   //press(x,y,1)
        sleep(1000)
        back()
        break
    }
      }else{
                    log('点同城|直播')
   id('tmk').findOne().click()
        sleep(3000)
      }
     
        
        
        
        
  
  }
  if (textContains('输入城市').exists()){
    log('切换城市')
    var a2 = textContains('输入城市').findOne().bounds().centerX();
    var a3 = textContains('输入城市').findOne().bounds().centerY();
    press(a2, a3, 1)   //press(x,y,1)
    sleep(1000)
     setText(位置名)
  }
  if (id('b02').exists()){
    log('确定选择')
    var a2 =id('b02').findOne().bounds().centerX();
    var a3 = id('b02').findOne().bounds().centerY();
    press(a2, a3, 1)   //press(x,y,1)
    sleep(1000)
     setText(位置名)
  }
  }
  sleep(1000)
  click(device.width/2,device.height/2)
  sleep(1000)
  } 
  function 随机数(minNum,maxNum) {
 
    switch(arguments.length){ 
        case 1: 
            return parseInt(Math.random()*minNum+1,10); 
        break; 
        case 2: 
            return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10); 
        break; 
            default: 
                return 0; 
            break; 
    } 
  
  }
启动抖音()
console.log(global.WEB_PARAMS)
进入同城()
评论数组=global.WEB_PARAMS.commentgztong.split('\n')


for (var i=0;i<global.WEB_PARAMS.gznumtong;i++) {

  swipeUp();

  if (text('点击进入直播间').exists()) {
    continue;
  }
  if (text('广告').exists()) {
    continue;
  }
  sleep(随机数(5000,8000))
  sleep(2000);
 if ( like()){
  log('已点赞')

 }
 if ( subscribe()){
  log('已关注')

 }
 if ( comment()){
  log('已私信')

 }
 sleep(随机数(1000,5000))

}
toastLog('任务完成')
//点赞
function like () {
  if (!global.WEB_PARAMS.dztong){
    return
  }
  var likeBtn = descContains('喜欢').visibleToUser().findOnce()


    likeBtn.click()
    sleep(2000);
    return true

}
//关注

function subscribe(){
  if (!global.WEB_PARAMS.gztong){
    return
  }
  var subscribeBtn=descContains('关注').visibleToUser().findOnce()

    subscribeBtn.click()
    sleep(2000);
    return true

}
function comment(){
  if (!global.WEB_PARAMS.sstong){
    return
  }
  var commentBtn=id('user_avatar').visibleToUser().findOnce()

    commentBtn.click()

    sleep(2000);
    desc('私信').findOne().click()
    sleep(2000);
    setText(评论数组[随机数(0,评论数组.length)]  )
    sleep(2000);
    desc('发送').findOne().click()
   back()
   sleep(2000);
   back()
   sleep(2000);
    return true

}